/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jmodcog2.component;

import jmodcog2.base.Runner;

/**
 *
 * @author Mitch
 */
public class PipelineNode implements Node {
    Runner origin;
    Runner target;

    public Runner getOrigin() {
        return origin;
    }

    public boolean setOrigin(Runner origin) {
        if (target == null || target.inputSize() == origin.outputSize()) {
            this.origin = origin;
            return true;
        }
        return false;
    }

    public Runner getTarget() {
        return target;
    }

    public boolean setTarget(Runner target) {
        if (origin == null || origin.outputSize() == target.inputSize()) {
            this.target = target;
            return true;
        }
        return false;
    }

    @Override
    public boolean send() {
        if (origin != null && target != null) {
            return target.process(origin.getOutput());
        }
        return false;
    }

    @Override
    public int originConnectionSize() {
        if (origin != null) {
            return origin.outputSize();
        }
        if (target != null) {
            return target.inputSize();
        }
        return -1;
    }

    @Override
    public int targetConnectionSize() {
        if (target != null) {
            return target.inputSize();
        }
        if (origin != null) {
            return origin.outputSize();
        }
        return -1;
    }
    
}
